<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <?php include_once MvcReg::$_moduleName . '/views/layout/head.php'; ?>
</head>
<body>
<?php include_once MvcReg::$_moduleName . '/views/layout/header.php'; ?>
<?php include_once MvcReg::$_moduleName . '/views/layout/top-nav.php'; ?>
<div id="main">
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-2">
                <?php include_once MvcReg::$_moduleName . '/views/layout/left_menu.php'; ?>
            </div>
            <div class="col-md-12">
                <div class="right-content">
                    <h3>
                        <?php echo $menu["breadcrumb_current"] ?>
                    </h3>
                    <br>
                    <form name="mainform" action="" method="get">
                        <?php echo $hidden_data ?>
                        <div class="table-responsive">
                            <div class="panel panel-default">
                                <div class="panel-body form-inline">
                                    <div class="form-group">
                                        <label>收货人手机号:</label>
                                        <input type="text" name="q_mobile"
                                               value="<?php echo $q_mobile ?>"
                                               class="form-control input-sm" placeholder=""/>
                                    </div>
                                    <div class="form-group">
                                        <label>预计送达时间:</label>
                                        <div class="input-group">
                                            <span class="input-group-addon">
                                                <span class="glyphicon glyphicon-calendar">
                                                </span>
                                            </span>
                                            <input size="16" type="text" name="q_from_date" readonly=""
                                                   class="form_datetime form-control"
                                                   value="<?php echo $q_from_date ?>">
                                            <span class="input-group-addon">
                                                至
                                            </span>
                                            <input size="16" type="text" name="q_to_date" readonly="" class="form_datetime form-control" value="<?php echo $q_to_date ?>">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label>配货单号:</label>
                                        <input type="text" name="q_phno" value="<?php echo $q_phno ?>" class="form-control input-sm" placeholder=""/>
                                    </div>
                                    <button type="submit" class="btn btn-primary"><span class="glyphicon glyphicon-search"></span>立即查询</button>
                                    <button style="float:right;" type="button" class="btn btn-primary" id="pl_del">批量删除</button>
                                </div>
                            </div>
                            <table class="table table-hover">
                                <thead>
                                <tr class="info">
                                    <th width="70px" style="text-align:center;"><label><input id="selectAll" name="" type="checkbox" value=""> <b>全选</b></label></th>
                                    <th>序</th>
                                    <th class="col-md-4">配送信息</th>
                                    <th class="col-md-4">订单信息</th>
                                    <th>配送记录</th>
                                    <th>操作区</th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php
                                $n = 0;
                                foreach ($rsp_list as $k => $row) {
                                    $n++;
                                    $item = $n + ($page - 1) * $number_page;
                                    $id = $row["id"];
                                    $distance = round($row['distance']/1000,2);
                                    $sty = '';
                                    if($distance >= 7){
                                        $sty = 'style="color:red"';
                                    }
                                    ?>
                                    <tr data-id="<?php echo $id ?>" id="<?php echo 'del_'.$id ?>" >
                                        <td><input class="xz_del" name="ids" type="checkbox" value="<?php echo $id ?>"></td>
                                        <td><?php echo $item ?></td>
                                        <td class="">
                                            <div>预计送达时间：<label  class="red"><?php echo $row["delivery_time"] ?></label>
                                            </div>
                                            <div>订货人：<?php echo $row["buyer"] ?></div>
                                            <div>收货人：<?php echo $row["receiver"] ?></div>
                                            <div>收货人手机号：<?php echo $row["receiver_tel"] ?></div>
                                            <div>收货地址：<?php echo $row["receiver_address"] ?></div>
                                            <div <?php echo $sty?>>预估公里数：<?php echo $distance ?> 公里</div>
                                            <div>经度：<?php echo $row["lng"] ?></div>
                                            <div>纬度：<?php echo $row["lat"] ?></div>
                                        </td>
                                        <td class="">
                                            <div>订单来源：<label class="red"><?php echo $row["source"] ?></label>
                                            </div>
                                            <div>
                                                <?php if (!empty($row['products'])) { ?>
                                                    <table style="margin: 5px;">
                                                        <th>商品名称</th>
                                                        <th style="padding-left:5px;">数量</th>
                                                        <?php
                                                        $p_ids = '';
                                                        foreach ($row['products'] as $pk => $pv) {
                                                            # 拼商品物料码
                                                            $p_ids .=  $pv['product_no'].',';
                                                            ?>
                                                            <tr>
                                                                <td><?php echo $pv["product_name"] ?></td>
                                                                <td style="padding-left: 5px;text-align: center;"><?php echo $pv["qty"] ?></td>
                                                            </tr>
                                                        <?php }?>
                                                    </table>
                                                <?php }
                                                ?>
                                            </div>
                                            <div>渠道运费：<?php echo $row["pos_fee"] ?></div>
                                            <div>配货单号：<?php echo $row["ph_no"] ?></div>
                                            <div>商家订单号：<?php echo $row['order_no']?></div>
                                            <div>买家备注：<?php echo $row["customre_memo"] ?></div>
                                            <div>卖家备注：<?php echo $row["seller_remarks"] ?></div>
                                            <div>POS生成订单：<?php echo $row["pos_no"] ?></div>
                                        </td>
                                        <td>
                                            <?php if (empty($row['express_orders'])) { ?>
                                                <div>无记录</div>
                                            <?php } else { ?>
                                                <div>
                                                    <table style="margin: 5px;">
                                                        <th>配送方</th>
                                                        <th style="padding-left:5px;">状态</th>
                                                        <th style="padding-left:5px;">推送信息</th>
                                                        <?php foreach ($row['express_orders'] as $eok => $eov) {
                                                          $res = json_decode($eov['push_response_data'],true);
                                                              $ress = $res['msg'];
                                                        ?>
                                                            <tr>
                                                                <td><?php echo Data::$_express_type[$eov["express_type"]] ?></td>
                                                                <td style="padding-left: 5px;text-align: center;"><?php echo Data::$_express_status[$eov["status"]];?></td>
                                                                <td style="padding-left: 5px;text-align: center;"><?php echo$ress;?></td>
                                                            </tr>
                                                        <?php } ?>
                                                    </table>
                                                </div>
                                            <?php } ?>
                                        </td>
                                        <td>
                                            <div>
                                                <?php
                                                $customre_memo = str_replace(array("\r\n", "\r", "\n"), "", $row['customre_memo']);
                                                $seller_remarks =str_replace(array("\r\n", "\r", "\n"), "", $row['seller_remarks']);
                                                ?>
                                                <button type="button" class="btn btn-primary" data-toggle="modal"
                                                        data-target="#setting"
                                                        onclick="settings('<?php echo $id ?>','<?php echo $row['delivery_time'] ?>','<?php echo $row['weight'] ?>','<?php echo $distance ?>','<?php echo $p_ids ?>','<?php echo $row['source'] ?>','<?php echo $seller_remarks.' '.$customre_memo ?>')">
                                                    订单指派
                                                </button>
                                            </div>
                                            <div style="margin-top: 10px;">

                                                <button type="button" class="btn btn-primary delorder"  data-id="<?php echo $id ?>"> 删除订单</button>

                                            </div>
                                            <div style="margin-top: 10px;">
                                                <button type="button" class="btn btn-primary"
                                                         onclick="OrderDetails('<?php echo $id ?>')">
                                                    查看订单详情
                                                </button>
                                            </div>
                                        </td>
                                    </tr>
                                <?php } ?>
                                </tbody>
                            </table>
                            <div class="page">
                                <div class="pagination pull-left">共<?php echo $total_count ?>笔记录</div>
                                <?php if (!empty($rsp_page_list)) echo $rsp_page_list; ?>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="pop_bg del_orders_bg" style="display: none;">
	<div class="del_orders_com">
    	<div class="title">删除订单原因</div>
        <form action="" method="get">
            <div class="com">
                <?php
                    foreach(Data::$_order_del as $k => $itm) {
                        echo  '<p><label><input type="radio" name="RadioGroup1" value="'.$k.'">'.$itm.'</label></p>';
                    }
                ?>
            </div>
            <div class="bnt">
            	<button type="button" class="btn btn-default" id="qx_del">取消删除</button>
                <button type="button" class="btn btn-primary" id="qr_del">确认删除</button>
            </div>
        </form>
    </div>
</div>
<script type="text/javascript">
$(document).ready(function(){
	//全选js
    var G = {
        pList:[],
    };

    $("#selectAll").click(function() {
	    if(G.pList.length > 0){
            G.pList = [];
        }
		$("input[name='ids']").prop("checked", this.checked);
        $("input[name='ids']:checkbox:checked").each(function () {
            if ($(this).is(':checked')) {
                G.pList.push($(this).val() );
            }
        });

    });
	$("input[name='ids']").click(function() {
		var $subs = $("input[name='ids']");
		$("#selectAll").prop("checked" , $subs.length == $subs.filter(":checked").length ? true :false);
        let id = $(this).val();
        if($.inArray(id,G.pList) >= 0){
            G.pList.splice($.inArray(id,G.pList),1);
        }else{
            G.pList.push(id);
        }

    });
	//删除订单
	$("#pl_del").click(function(){
		$(".del_orders_bg").fadeIn();
	});

	$(".delorder").click(function(){
		$(".del_orders_bg").fadeIn();
		let did = $(this).attr('data-id');
        G.pList.push(did)
	});


	$("#qx_del").click(function(){
		$(".del_orders_bg").fadeOut();
	});




	$("#qr_del").click(function(){
		$(".del_orders_bg").fadeOut();
		G.r_del = $("input[name='RadioGroup1']:checked").val();
		if($.isArray(G.pList)){
		    if(G.pList.length <= 0){
                alert('请先选择需要删除的订单！');
                return false;
            }
        }else{
            alert('请先选择需要删除的订单！');
            return false;
        }
		if(typeof(G.r_del) == 'undefined'){
            alert('请先选择删除订的单理由！');
            return false;
        }

        $.ajax({
            url:'?md=shop&cl=ajax&at=delOrders',
            dataType:'json',
            data:{list:G.pList,r_del:G.r_del},
            type:'post',
            success:function (d) {
                alert(d.msg);
                if(d.status == 'success'){
                    G.pList = [];
                    $(d.success_ids).each(function (k,v) {
                        $("#del_"+v).remove();
                    })
                }
                window.location.reload();
            }
        })

    });
});
</script>

<?php include_once MvcReg::$_moduleName . '/views/layout/footer.php'; ?>
<?php include_once MvcReg::$_moduleName . '/views/dialog/express_order_setting.php'; ?>
<?php include_once MvcReg::$_moduleName . '/views/dialog/del_order.php'; ?>
<script>

</script>
</body>
</html>
